package com.li.hsanguosha.controller;

import com.li.hsanguosha.pojo.Result;
import com.li.hsanguosha.pojo.User;
import com.li.hsanguosha.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {

    @Autowired
    private UserService userService;


    @PostMapping("/user/register")
    public Result register(String username, String password,String nickname) {
        //验证用户名密码昵称不为空
        User u = userService.findUserByName(username);
        if(u == null) {
            //而空 可注册
            userService.register(username,password,nickname);
            return Result.success();
        }else{
            //不为空 返回
            return Result.error("用户名已存在");
        }
    }
}
